﻿using SprayingRobot.Test;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Expression = System.Linq.Expressions.Expression;

namespace 测试反射的方式
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            测试.测试洗枪频率();
           Type type = typeof(int);
            Type type1= typeof(Func<int>);
            //var c= type1.GetGenericParameterConstraints();
            var c2= type1.GetGenericArguments();
            Type c3= type1.GetGenericTypeDefinition();
            var c4= c3.MakeGenericType(typeof(string));
            //type.GetInterfaceMap();
        }

        private void GetResult(Exception exArgument)
        {
            Type typeExpression = typeof(Expression);
            Type[] types = new Type[] { typeExpression, typeof(ParameterExpression[]) };
            MethodInfo lambdaMethodInfo = typeExpression.GetMethod(nameof(Expression.Lambda), 1, BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Static, null, types, null);

            //typeof(Func<int>).GetGenericTypeDefinition().MakeGenericType(exArgument);
            dynamic ex = exArgument;
            Type typeArgument = ex.Type;
            var realMethod = lambdaMethodInfo.MakeGenericMethod(typeof(Func<object>));
            

            var dddInvoke = realMethod.Invoke(null, new object?[] { exArgument, null });
            Expression<Func<object>> ddd = dddInvoke as Expression<Func<object>>;
            var result = ddd.Compile()();
        }
    }
}
